var ns, UIAlbumBrowser, bmLocation;
app = new Vue({
    el: '#app',
    data: {
        list: [],
        form: {
            pageindex: 0,
            pagesize: 10,
            PlanType: 4,
            TaskStatus: 0//0-未开始,1-进行中,2-已结束
        },
        total: {
            ProcessCount: 0,
            UnStart:0,
            Doing:0,
        },
        current_item_length: 0,
        scroll_top: 0,
        can_scroll: false,
        showTop:false,
        showsearch:false,
    },
    methods: {
        //获取顶部数量
        get_data_count:function(){
            var that = this;
            var options = {};
            options.action = "get_environment_clean_planlist_total";
            options.Keywords='';
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if(data.status){
                        that.total.UnStart = data.UnStart;
                        that.total.Doing = data.Doing;
                    }
                   
                } else if (err) {
                    that.total.UnStart = 0;
                    that.total.Doing = 0;
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
        },
        get_data: function () {
            var that = this;
            that.get_data_count();
            if (that.form.status == 2) {
                return;
            }
            that.can_scroll = false;
            var options = {};
            // options.action = "getequipmentlist";
            // options.pagesize = that.form.pagesize;
            // options.pageindex = that.form.pageindex;
            // options.PlanType = that.form.PlanType;
            // options.TaskStatus = that.form.TaskStatus;
            options.action = "get_environment_clean_planlist";
            options.pagesize = that.form.pagesize;
            options.pageindex = that.form.pageindex;
            options.PlanType = that.form.PlanType;
            options.Status = that.form.TaskStatus;
            options.Keywords='';
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if (data.list.length == that.form.pagesize) {
                        that.can_scroll = true;
                    }
                    if (that.form.pageindex == 0) {
                        that.list = data.list;
                    } else {
                        that.list = that.list.concat(data.list);
                    }
                    app.current_item_length = that.list.length
                    // that.total.ProcessCount = data.ProcessCount;
                    // that.total.UnStart = data.UnStart;
                    // that.total.Doing = data.Doing;
                } else if (err) {
                    that.list = [];
                    that.current_item_length = 0;
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        select_status: function (status) {
            var that = this;
            that.showTop=false;
            that.form.TaskStatus = status;
            that.form.pageindex = 0;
            that.list = [];
            that.get_data();
        },
        open_list: function (item) {
            var that = this;
            var url = 'bjlh_list_frm';
            var title = item.DevicePlanName;
            // if (item.TaskStatus == 1) {
            //     url = 'bjlh_summary_frm';
            //     title = '任务详情';
            // }
            ns.openWin(url, title, {
                id: item.ID
            });
        },
        open_add: function () {
            var that = this;
            ns.openWin('bjlh_addfrm', '新增记录');
        },
        open_history:function(){
            var that = this;
            ns.openWin('bjlh_list_Record', '环境保洁');
        },
        open_select:function(){
            var that=this;
            that.showTop=!that.showTop;
        },
        doHideSearch:function(){
            var that=this;
            that.showTop=false;
            that.showsearch=false;
        },
        select_allstatus:function(){
            var that=this;
            that.showsearch=!that.showsearch;
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.form.status = api.pageParam.status || 1;
    setTimeout(function () {
        app.form.status = 1;
        app.get_data();
        setTimeout(function () {
            ns.init_pull();
        }, 500)
    }, 500)
    api.addEventListener({
        name: 'do_open_fee_history'
    }, function (ret, err) {
        app.open_history();//打开工作报告
    });
    api.addEventListener({
        name: 'devicetaskcomplete'
    }, function (ret, err) {
        app.get_data();
    });
    api.addEventListener({
        name: 'startplantaskdone'
    }, function (ret, err) {
        app.get_data();
    });
    api.addEventListener({
        name: 'do_open_add'
    }, function (ret, err) {
        app.open_add();
    });
    api.addEventListener({
        name: 'do_open_select'
    }, function (ret, err) {
        app.open_select();
    });
};
